class ClassOperate {

    constructor() { }

    // 单例
    static of(){
        if(!this._instance){
            this._instance = new ClassOperate()
        }
        return this._instance
    }

    // 是否有某个 className
    hasClassName(elem, name) {
        let tmpName = elem.className;
        let tmpReg = new RegExp(name, 'g');
        if (tmpReg.test(tmpName)) {
            return true;
        } else {
            return false;
        }
    }

    // 添加 className
    addClass(elem, className) {
        if (!new RegExp("(^|\\s)" + className + "(\\s|$)").test(elem.className)) elem.className += ' ' + className;
    }

    // 移除 className
    removeClass(elem, className) {
        elem.className = elem.className.replace(new RegExp("(^|\\s)" + className + "(?=(\\s|$))", "g"), '');
    }

}
export default ClassOperate